﻿<!DOCTYPE html>
<html>
<head>
    <!-- basic -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- mobile metas -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <!-- site metas -->
    <title>KingCity管理后台</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- site icon -->
    <!--<link rel="icon" href="images/fevicon.png" type="image/png" />-->
    <!-- bootstrap css 左侧下拉有更多-->
    <link rel="stylesheet" href="css/bootstrap.min.css" />
    <!-- site css -->
    <link rel="stylesheet" href="style.css" />
    <!-- responsive css 使边上的缩放-->
    <link rel="stylesheet" href="css/responsive.css" />

</head>
<body class="inner_page tables_page">

    <script src="./js/jquery-2.2.3.min.js"></script>
    <script>
        $(document).ready(function () {

                //获取pro_id
                //将地址从"？"位置分割成两部分          
                var turl = decodeURI(window.location.href);
                var arr = turl.split('?');
                //alert(turl);
                //取地址右边参数部分从"&"位置继续分割，成为单独参数列表（不过只有id一个参数）
                var params = arr[1].split('&'); //得到[a=1,b=2,c=3]
                //定义一个空对象
                var obj = {};
                for (var i = 0; i < params.length; i++) {
                    var param = params[i].split('='); //得到[id,id值]
                    obj[param[0]] = param[1]; //为对象赋值
                }
            var pro_id = obj["pro_id"];
     
            $('#pro_id').val(pro_id);
            var a = $('#pro_id').val();


            var html = '';
            $.ajax({
                type: 'get',
                url: "http://localhost:50364/api/Admin/Inventory/SKUlist",
                data: {"pro_id":a},
                success: function (data) {
                   
                    for (var i = 0; i < data.length; i++) {
                        
                       
                        html += "<tr id='sku'>" +
                            "<td id='sku_id'>" + JSON.stringify(data[i]["SKU_Id"]) + "</td><td>" 
                            + JSON.stringify(data[i]["SKU_Label"]) + "</td><td>"
                            + JSON.stringify(data[i]["SKU_2rdLabel"]) + "</td><td>" 
                            + JSON.stringify(data[i]["SKU_Cost"]) + "</td><td>" 
                            + JSON.stringify(data[i]["SKU_RefPrice"]) + "</td><td>"
                            + JSON.stringify(data[i]["SKU_CrtPrice"]) + "</td><td>"                    
                            + JSON.stringify(data[i]["SKU_WrnStock"]) + "</td><td>" +
                            "<button type='button' id='update' class='btn cur - p btn - primary'>修改</button>" +
                            "<button type='button' class='btn cur - p btn - danger' id='delete' style='background-color:#DC3545;color:#FFFFFF'>删除</button>" +
                            "</td>";                 
                        
                    }
                   $(skulist).append(html);
                }
            });
        })

        $(document).on('click', '#update', function () {
            sku_id = $(this).closest('#sku').find('#sku_id').text();
           // alert($(this).closest('#goods').find('#pro_id').text());
            url = "./SKU_upload.html?sku_id=" + sku_id ;
            window.location.href = url;
         
        })


        $(document).on('click', '#add', function () {
            var pro_id = $('#pro_id').val();
            url = "./SKU_add.html?pro_id=" + pro_id;
            window.location.href = url;

        })

        $(document).on('click', '#delete', function () {
            var sku_id = $(this).closest('#sku').find('#sku_id').text();
            var pro_id = $('#pro_id').val();
            var url = "http://localhost:50364/api/Admin/Inventory/DeleteSKU";
            $.ajax({
                //几个参数需要注意一下
                type: "get",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: url,
                data: {
                    "sku_id": sku_id,
                    "pro_id": pro_id,
                },
                success: function (result) {
                    alert("删除成功");
                    location.reload();
                },
                error: function () {
                    alert("异常！");
                }
            });
            

        })


    </script>
    <div class="full_container">
        <div class="inner_container">
            <!-- Sidebar 侧边栏 -->
            <nav id="sidebar">
                <div class="sidebar_blog_2">
                    <h4>商城管理后台</h4>
                    <ul class="list-unstyled components">
                        <li class="active">
                            <a href="#dashboard" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"><i class="fa fa-dashboard yellow_color"></i> <span>商品管理</span></a>
                            <ul class="collapse list-unstyled" id="dashboard">
                                <li>
                                    <a href="">> <span>商品管理</span></a>
                                </li>
                                <li>
                                    <a href="">> <span>产品统计</span></a>
                                </li>
                            </ul>
                        </li>
                        <li>
                            <a href="#element" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"><i class="fa fa-object-group blue2_color"></i> <span>交易管理</span></a>
                            <ul class="collapse list-unstyled" id="element">
                                <li><a href="order_list.html">> <span>订单列表</span></a></li>
                                <li><a href="">> <span>发货管理</span></a></li>

                            </ul>
                        </li>
                        <li><a href="widgets.html"><i class="fa fa-map purple_color2"></i> <span>优惠券管理</span></a></li>
                        <li><a href="widgets.html"><i class="fa fa-diamond orange_color"></i> <span>用户管理</span></a></li>
                        <li>
                            <a href=""><i class="fa fa-clone yellow_color"></i> <span>退出</span></a>
                        </li>
                    </ul>
                </div>
            </nav>
            <!-- end sidebar -->
            <!-- right content -->
            <div id="content">
                <!-- topbar 上边框 -->
                <div class="topbar">
                    <nav class="navbar navbar-expand-lg navbar-light">
                        <div class="full">
                            <button type="button" id="sidebarCollapse" class="sidebar_toggle"><i class="fa fa-bars"></i></button>

                            <div class="right_topbar">
                                <div class="icon_info">
                                    <ul>
                                        <li><a href="#"><i class="fa fa-bell-o"></i><span class="badge"></span></a></li>
                                        <li><a href="#"><i class="fa fa-sign-out"></i><span class="badge"></span></a></li>
                                    </ul>

                                </div>
                            </div>
                        </div>
                    </nav>
                </div>
                <!-- end topbar -->
                <!-- dashboard inner -->
                <div class="midde_cont">
                    <div class="container-fluid">
                        <div class="row column_title">
                            <div class="col-md-12">
                                <div class="page_title">
                                    <h2>SKU管理  <button type="button" class="btn cur-p btn-secondary" id="add">添加SKU</button></h2>
                                    <input id="pro_id" type="hidden"/>
                             
                                </div>
                              
                            </div>
                        </div>
                        <!-- row 中间填一些表格或者商品行-->
                        <div class="row">
                            <table class="gallery table table_list table_striped table-bordered " id="tableList" style=" text-align: center; ">
                                <thead>
                                    <tr>
                                        <!--<th width="50px"><label class="checkbox relative"><input type="checkbox" class="ace" name="checkbox"><span class="lbl"></span></label></th>-->
                                     
                                        <th width="160">SKU_Id</th>
                                        <th width="160">标签1</th>
                                        <th width="160">标签2</th>
                                        <th width="160">成本</th>
                                        <th width="160">参考价（原价）</th>
                                        <th width="160">现价</th>
                                        <th width="160">库存数量</th>


                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="skulist">
                                </tbody>
                            </table>

                        </div>
                    </div>
                </div>
                <!-- end dashboard inner -->
            </div>
        </div>
    </div>
    <!-- jQuery -->





</body>
</html>